wifi.eventmon.register(wifi.eventmon.STA_CONNECTED, function(T)
    print("\n\tSTA - CONNECTED".."\n\tSSID: "..T.SSID.."\n\tBSSID: "..T.BSSID.."\n\tChannel: "..T.channel)
    print(wifi.sta.getip())
    print("Wifi Connected")
    tcp = net.createConnection()
    -- 创建接收数据的事件回调
    tcp:on("receive",function (sck,d)
        print("Recv:"..d)
        -- spl = split(d,',')
        -- print(spl[0])
        if d=="1,open" then
            print("GPIO ".." Opened")
        end
    end)
    -- 创建链接建立事件的监听
    tcp:on("connection",function(sck,c)
        -- tcp:send("connected")
        print("TCP connecte")
        mytimer = tmr.create()
        mytimer:register(1000, tmr.ALARM_AUTO, function() 
            tcp:send('heart')
        end)
        mytimer:interval(3000) -- actually, 3 seconds is better!
        mytimer:start()
    end)
    -- 链接到服务器
    tcp:connect(9001,"39.98.79.122")
    print("Start TCP Connection")
end)

--配置wifi
function wifi_config(ssid,pwd)
    station_cfg={}
    station_cfg.ssid=ssid
    station_cfg.pwd=pwd
    station_cfg.save=true
    station_cfg.auto=true
    wifi.sta.config(station_cfg)
    print("connecting ")
end
function split( str,reps )
    local resultStrList = {}
    string.gsub(str,'[^'..reps..']+',function ( w )
        table.insert(resultStrList,w)
    end)
    return resultStrList
end
wifi.sta.setip({ip="192.168.137.253",netmask="255.255.255.0",gateway="192.168.137.1"})
wifi_config("test","12345678")